<?php
/**
 * Created by PhpStorm.
 * User: VJLau
 * Date: 2018/2/5
 * Time: 下午12:29
 */

$id = intval($_GPC['id']);
$search = $_GPC['search'];
$uniacid = $_W['uniacid'];
if (empty($id)) message('参数错误', $this->createMobileUrl('list'), 'error');

// 目的地
$dest = pdo_fetch("select * from " . tablename('bontrip_dest') . " where uniacid = '{$uniacid}' AND id={$id} and deleted_at is null");
if (empty($dest)) message('目的地不存在或已删除！', $this->createMobileUrl('list'), 'error');
if (!empty($dest['thumbs'])) {
    $dest['thumbs'] = unserialize($dest['thumbs']);
}
if (empty($search)) {
    //一日游
    $pindex = max(1, intval($_GPC['page']));
    $psize = 2;
    $qualitys = pdo_fetchall("SELECT ql.*,currency.exchange_rate FROM " . tablename('bontrip_quality')
        . " AS ql LEFT JOIN " . tablename('bontrip_currency') . " AS currency ON currency.id = ql.currency_id"
        . " RIGHT JOIN " . tablename('bontrip_quality_dest') . "AS qd ON ql.id = qd.quality_id"
        . " WHERE ql.uniacid = '{$uniacid}' AND qd.dest_id = '{$id}' and ql.deleted_at is null"
        . " ORDER BY ql.sort ASC,ql.id DESC LIMIT "
        . ($pindex - 1) * $psize . ',' . $psize);
    $total = pdo_fetchcolumn("SELECT COUNT(*)FROM " . tablename('bontrip_quality')
        . " AS ql LEFT JOIN " . tablename('bontrip_currency') . " AS currency ON currency.id = ql.currency_id"
        . " RIGHT JOIN " . tablename('bontrip_quality_dest') . "AS qd ON ql.id = qd.quality_id"
        . " WHERE ql.uniacid = '{$uniacid}' AND qd.dest_id = '{$id}' and ql.deleted_at is null");
    $max_page = ceil($total / $psize);
    $is_next = true;

    if ($max_page <= $pindex) {
        $is_next = false;
    }
} else {
    $qualitys = pdo_fetchall("SELECT ql.*,currency.exchange_rate FROM " . tablename('bontrip_quality')
        . " AS ql LEFT JOIN " . tablename('bontrip_currency') . " AS currency ON currency.id = ql.currency_id"
        . " RIGHT JOIN " . tablename('bontrip_quality_dest') . "AS qd ON ql.id = qd.quality_id"
        . " WHERE ql.uniacid = '{$uniacid}' AND qd.dest_id = '{$id}' and ql.deleted_at is null and ql.name LIKE '%{$search}%'"
        . " ORDER BY ql.sort ASC,ql.id DESC");
}

$title = $dest['name'];
if (empty($search)) {
    include $this->template('quality');
} else {
    include $this->template('quality_search');

}